package cn.wolfcode.education.web.controller;

import cn.wolfcode.education.anno.PermissionName;
import cn.wolfcode.education.domain.Trace;
import cn.wolfcode.education.service.ITraceService;
import cn.wolfcode.education.util.JSONResult;
import cn.wolfcode.education.util.PageResult;
import org.apache.shiro.authz.annotation.RequiresPermissions;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;

@Controller
@RequestMapping("/trace")
public class TraceController {

    @Autowired
    private ITraceService traceService;

    @RequiresPermissions("trace:view")
    @PermissionName("跟进查看")
    @RequestMapping("")
    public String list() {
        return "trace";
    }

    @RequiresPermissions("trace:view")
    @PermissionName("跟进情况列表")
    @RequestMapping("query")
    @ResponseBody
    public PageResult query() {
        return traceService.query();
    }

    @RequestMapping("traceClient")
    @ResponseBody
    public JSONResult traceClient(Trace trace) {
        JSONResult result = new JSONResult();
        try {
            traceService.inset(trace);
            return result;
        } catch (Exception e) {
            e.printStackTrace();
            result.setMsg("程序出异常");
            return result;
        }
    }

    @RequiresPermissions("trace:audit")
    @PermissionName("跟进审核")
    @RequestMapping("audit")
    @ResponseBody
    public JSONResult audit(Long traceId, Long level, String auditAssess) {
        JSONResult result = new JSONResult();
        traceService.audit(traceId, level, auditAssess);
        return result;
    }


}
